﻿namespace Shop.Model.Dto.Hea;

public class HealthRiskHitRatioDto
{
    /// <summary>
    /// 风险结果（Hea_RiskResult）ID
    /// </summary>
    public long ID { get; set; }

    /// <summary>
    /// 百分比
    /// </summary>
    // [JsonConverter(typeof(NumberConverter), NumberConverterShip.Double)]
    // [JsonProperty(PropertyName = "GName")]
    public int Percentage { get; set; } = 0;

    /// <summary>
    /// 风险
    /// </summary>
    public HealthRiskResultDto RiskResult { get; set; }

    private double? bmi = null;

    /// <summary>
    /// BMI
    /// </summary>
    public double? Bmi
    {
        set
        {
            if (bmi == null)
                bmi = value;
            switch (this.RiskResult.Type)
            {
                case 1: //肠胃
                    if (bmi < 18.5)
                        Percentage += 4;
                    else if (bmi >= 24 && bmi <= 27.9)
                        Percentage += 4;
                    else if (bmi >= 28)
                        Percentage += 8;
                    break;
                case 2: //代谢
                    if (bmi < 18.5)
                        Percentage += 10;
                    else if (bmi >= 24 && bmi <= 27.9)
                        Percentage += 10;
                    else if (bmi >= 28)
                        Percentage += 20;
                    break;
                case 3: //心血
                    if (bmi < 18.5)
                        Percentage += 5;
                    else if (bmi >= 24 && bmi <= 27.9)
                        Percentage += 5;
                    else if (bmi >= 28)
                        Percentage += 10;
                    break;
                case 4: //肝肾
                    if (bmi < 18.5)
                        Percentage += 10;
                    else if (bmi >= 24 && bmi <= 27.9)
                        Percentage += 8;
                    else if (bmi >= 28)
                        Percentage += 10;
                    break;
                case 5: //免疫
                    if (bmi < 18.5)
                        Percentage += 3;
                    else if (bmi >= 24 && bmi <= 27.9)
                        Percentage += 3;
                    else if (bmi >= 28)
                        Percentage += 5;
                    break;
                case 6: //四高
                    if (bmi < 18.5)
                        Percentage += 5;
                    else if (bmi >= 24 && bmi <= 27.9)
                        Percentage += 8;
                    else if (bmi >= 28)
                        Percentage += 10;
                    break;
            }
        }
    }

    private double? bmr = null;

    /// <summary>
    /// BMR
    /// </summary>
    public double? Bmr
    {
        set
        {
            if (bmr == null)
                bmr = value;
            double bmr_1 = 0.00, bmr_2 = 0.00;
            if (Sex == "男")
            {
                bmr_1 = 1442.83;
                bmr_2 = 1647.53;
            }
            else
            {
                bmr_1 = 1154.37;
                bmr_2 = 1415.19;
            }

            switch (this.RiskResult.Type)
            {
                case 1: //肠胃
                    if (bmr < bmr_1)
                        Percentage += 4;
                    else if (bmr > bmr_2)
                        Percentage += 4;
                    break;
                case 2: //代谢
                    if (bmr < bmr_1)
                        Percentage += 10;
                    else if (bmr > bmr_2)
                        Percentage += 10;
                    break;
                case 3: //心血
                    if (bmr < bmr_1)
                        Percentage += 10;
                    else if (bmr > bmr_2)
                        Percentage += 5;
                    break;
                case 4: //肝肾
                    if (bmr < bmr_1)
                        Percentage += 10;
                    else if (bmr > bmr_2)
                        Percentage += 10;
                    break;
                case 5: //免疫
                    // if (bmr < 1442.83)
                    //     Percentage += 4; 
                    // else if (bmr > 1647.53)
                    //     Percentage += 4; 
                    break;
                case 6: //四高
                    if (bmr < bmr_1)
                        Percentage += 10;
                    else if (bmr > bmr_2)
                        Percentage += 10;
                    break;
            }
        }
    }


    public int Age
    {
        set
        {
            if (this.RiskResult.Type == 5)
            {
                if (value >= 30 && value < 50)
                    Percentage += 2;
                else if (value >= 50)
                    Percentage += 5;
            }
        }
    }

    public string Sex { get; set; }
}